﻿$(document).ready(function () {
    xGetViTriVip();
    //
    $('.ddlViTriHienThi').change(function () {
        xSetValueViTriVip();
        xTinhTien();
    });
    //
    $('.ddlSoNgayHienThi').change(function () {
        xTinhTien();
    });
    //
    clickUpVIP();
});

//Set gold and avatar
function xSetValueViTriVip() {
    $(".price_vip").text($('.ddlViTriHienThi').find('option:selected').attr('gold'));
    $(".anh-demo").attr('src',($('.ddlViTriHienThi').find("option:selected").attr('avatar')));
}

//Tính tiền
function xTinhTien() {
    var iGia = $('.price_vip').text();
    var iSoNgay = $('.ddlSoNgayHienThi').val();
    $('.gold-pay').text(parseInt(iGia) * parseInt(iSoNgay));
}

//LOAD DANH SÁCH VỊ TRÍ VIP
function xGetViTriVip() {
    $.ajax({
        type: "POST",
        url: "/Default.aspx/fncGetDropViTriVip",
        data: '{iType:1}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var Data = response.d;
            $('.ddlViTriHienThi').html(Data);
            xSetValueViTriVip();
        },
        failure: function (response) {
            //alert("failure: " + response.d);
        },
        error: function (response) {
            //alert("error: " + response.d);
        }
    });
}

function clickUpVIP()
{
    $('#up-vip').click(function () {
        var dtStartDate = $("#startDate").val();
        $('#notifition').slideDown("fast");
        $('#notifition .msg-page').text('Đang xử lý dữ liệu...');
        $.ajax({
            type: "POST",
            url: "/Default.aspx/fcnUpTinVip",
            data: '{strPTID:"' + $('.lblPT_ID').text() + '"' // Mã tin
                + ',strUSID:"' + $('.hdUS_ID').val() + '"'
                + ',strGVID:"' + $('.ddlViTriHienThi').val() + '"'
                + ',iSongayhienthi:' + $('.ddlSoNgayHienThi').val()
                + ',dtNgaybatdauhienthi:"' + dtStartDate + '"'
                + ',iGiaTien:' + $('.gold-pay').text() + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                var strResult = response.d;
                if (strResult == "") {
                    $('#notifition').slideUp("fast");
                    alert("Up tin Vip thành công.");
                    parent.$.colorbox.close();
                } else {
                    $('#notifition .msg-page').text(strResult);
                }
            },
            failure: function (response) {
                //alert("failure: " + response.d);
            },
            error: function (response) {
                //alert("error: " + response.d);
            }
        });
    });
}

